//
//  LineBtnView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/30.
//

#import "LineBtnView.h"
#import "CommonUtil.h"

@interface LineBtnView()
@property (strong, nonatomic) UILabel * titleLabel;
@property (strong, nonatomic) UIView * lineView;


@property (strong, nonatomic) UIButton * btn2;
@property (strong, nonatomic) UIButton * btn3;
@end

@implementation LineBtnView


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.lineView];

    }
    return self;
}

-(void)setType:(NSString *)type{
    _type = type;
    self.titleLabel.text = type;
    
    CGFloat w = (self.width-self.titleLabel.width-AD(40))/3;
    NSArray *titles = @[];
    if ([type isEqualToString:@"挑战周期"]) {
        titles = @[@"5期",@"10期",@"20期"];
    }else if ([type isEqualToString:@"挑战难度"]){
        titles = @[@"5对3",@"5对4",@"5对5"];
    }else if ([type isEqualToString:@"挑战级别"]){
        titles = @[@"免费",@"10元",@"100元"];
    }else if ([type isEqualToString:@"可得奖励"]){
        titles = @[@"可免费得3元彩金"];
    }else if ([type isEqualToString:@"榜单"]){
        titles = @[@"总榜",@"5期榜",@"10期榜",@"20期榜"];
        w = (self.width-self.titleLabel.width-AD(50))/4;
    }else if ([type isEqualToString:@"排序"]){
        titles = @[@"总期数",@"正确率",@"最新发表"];
    }else if ([type isEqualToString:@"状态"]){
        titles = @[@"全部",@"只看免费",@"只看收费"];
    }else if ([type isEqualToString:@"更多"]){
        titles = @[@"只看名人",@"全部战绩",@"高级筛选"];
    }
    
    
    for (NSInteger i = 0; i < titles.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:titles[i] forState:UIControlStateNormal];
        [btn setTitleColor:RGB(255.0, 48.0, 93.0) forState:UIControlStateSelected];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:AD(16)];
        btn.layer.cornerRadius = AD(3);
        btn.layer.borderColor = [[UIColor blackColor] colorWithAlphaComponent:0.1].CGColor;
        btn.layer.borderWidth = AD(1.5);
        [self addSubview:btn];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        if (i == 0) {
            [self btnClick:btn];
        }
        if (titles.count == 1) {
            btn.frame = CGRectMake( self.titleLabel.right + AD(10), AD(10), self.width-self.titleLabel.width-AD(20), AD(40));
        }else{
            btn.frame = CGRectMake( self.titleLabel.right + AD(10) + (i * (w + AD(10))), AD(10), w, AD(40));
        }
    }
    
    
}

- (void)btnClick:(UIButton *)sender{
    self.selectBtn.selected = false;
    self.selectBtn.layer.borderColor = [[UIColor blackColor] colorWithAlphaComponent:0.1].CGColor;
    self.selectBtn = sender;
    self.selectBtn.selected = YES;
    self.selectBtn.layer.borderColor = [RGB(255.0, 48.0, 93.0) colorWithAlphaComponent:0.2].CGColor;
}

#pragma mark - lazy
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, AD(100), self.height)];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = [UIFont systemFontOfSize:AD(18)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.text = @"三肖";
        _titleLabel.backgroundColor = RGB(243.0, 243.0, 243.0);
    }
    return _titleLabel;
}


-(UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0,self.height-AD(1),self.width, AD(1))];
        _lineView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    }
    return _lineView;
}

@end
